package com.dengqi.mymodule.activity.fragment;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;

import com.dengqi.mymodule.BaseActivity;
import com.dengqi.mymodule.R;
import com.dengqi.mymodule.activity.fragment.fragment.RecycleFragment;
import com.dengqi.mymodule.activity.fragment.tabframe.QTabFrameLayout;
import com.dengqi.mymodule.fragment.PictureFragment;
import com.dengqi.mymodule.fragment.TypeFragment;
import com.dengqi.mymodule.fragment.VideoFragment;
import com.module.retrofit.utils.ToastUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import androidx.fragment.app.Fragment;


public class QTabHostActivity extends BaseActivity{

    private String[] titles = {"首页", "附近", "发现", "我的"};
    private int images[] = {R.drawable.tab_home_selector, R.drawable.tab_shops_selector, R.drawable.tab_shopcart_selector, R.drawable.tab_mine_selector};
    private Fragment[] fragments= {RecycleFragment.newInstance(), PictureFragment.getIntance(), TypeFragment.getIntance(), VideoFragment.getIntance()};
//    private List<Fragment> fragments;
    private QTabFrameLayout mTabFrameLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment_q_tabhost);
        mTabFrameLayout = findViewById(R.id.tabFrameLayout);

        //模拟数据
        List<QTabFrameLayout.TabBean> tabBeanList = new ArrayList<>();
        for (int i = 0; i < titles.length; i++) {
            QTabFrameLayout.TabBean tabBean = new QTabFrameLayout.TabBean();
            tabBean.setTitle(titles[i]);
            tabBean.setTextRes(R.color.tab_bb2red);
            tabBean.setNum(0);
            tabBean.setIconRes(images[i]);
            tabBeanList.add(tabBean);
        }

        //设置参数
        mTabFrameLayout.setTabLayoutBackground(R.color.white);
        mTabFrameLayout.setTabViewData(getSupportFragmentManager(), tabBeanList, Arrays.asList(fragments));
        mTabFrameLayout.setTabViewClickListener(new QTabFrameLayout.OnItemClickListener() {
            @Override
            public boolean onItemClick(int position) {
                ToastUtil.showToast(position+"");
                if(position==1){
                    return true;
                }
                return false;
            }
        });
        mTabFrameLayout.setCenterView(R.mipmap.ic_launcher, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtil.showToast("中心");
            }
        });



        //模拟手动设置数字
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mTabFrameLayout.setTabViewNumByIndex(3, 5);
            }
        }, 1500);
    }


}
